
package andre.grids.util;

/**
 *
 * @author andre
 */
public final class PathUtils {
    public static String win32PathToUnix(String windowsPath)
    {
        if (isWindowsFullPath(windowsPath))
        {
            return windowsPath.substring(2, windowsPath.length()).replace('\\', '/');
        }
        return windowsPath.replace('\\', '/');
    }
    
    public static boolean isWindowsFullPath(String path)
    {
        if (path.substring(0,1).equals("/"))
            return false;
        return path.substring(1,2).equals(":");
    }
    
    public static String extractParentPath(String path)
    {
        int i = path.lastIndexOf("/");
        if (i == 0)
            return "/";
        else
        {
            return path.substring(0,i);
        }
    }
    
    public static String toDirectoryFilter(String dirName) {
        if (dirName == null || dirName.equals(""))
            return "/.*";
        return dirName + (dirName.endsWith("/")?"":"/") + ".*";
    }
}
